package com.lian.servlet;

import com.lian.service.impl.workserviceimpl;
import com.lian.service.workservice;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by lenovo on 2018/8/1.
 */
public class IndexServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        workservice ser=new workserviceimpl();
        int size=3;//定义一个变量来显示多少行出来
        int page=0;//从第几行开始
        if(request.getParameter("page")!=null){
            page=Integer.parseInt(request.getParameter("page"));
        }
        if(page<0){ //限制页码不能小于0
            page=0;
        }
        int count=ser.findCount();//总长度
        int maxpage=(count+size-1)/size;
        //限制最大页码不能超过查出来的页码
        if(page>maxpage-1){
            page=maxpage-1;
        }
        request.setAttribute("list", ser.findwork(page*size, size));
        request.setAttribute("page", page);
        request.getRequestDispatcher("show.jsp").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
